<?php
$title = '我的资产';
/** @var array $portfolio */
require __DIR__ . '/../partials/head.php';
require __DIR__ . '/../partials/nav.php';
?>
<section class="section">
    <div class="app-container" style="display:flex;flex-direction:column;gap:24px;">
        <div class="card" style="gap:16px;">
            <div>
                <h2 style="margin:0;">账户快照</h2>
                <p style="color:var(--text-secondary);margin:0;">数据来自 hummingbot-api · Asia/Tokyo</p>
            </div>
            <div class="grid-2">
                <div>
                    <h4>权益</h4>
                    <p style="font-size:1.8rem;margin:8px 0;"><?= 
                        Frontend\Helpers\Format::money($portfolio['total_equity'] ?? ($portfolio['portfolio_value'] ?? 0))
                    ?></p>
                    <p style="color:var(--text-secondary);">可用余额：<?= 
                        Frontend\Helpers\Format::money($portfolio['available_balance'] ?? ($portfolio['balances']['available'] ?? 0))
                    ?></p>
                </div>
                <div>
                    <h4>风控提示</h4>
                    <ul style="color:var(--text-secondary);padding-left:16px;margin:8px 0;line-height:1.6;">
                        <li>确保交易所 API 权限正确且额度充足。</li>
                        <li>建议开启全局开关前先在纸盘验证。</li>
                        <li>如需紧急停单，可在“我的设置”关闭自动化。</li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="card" style="gap:16px;">
            <h3 style="margin:0;">持仓与余额</h3>
            <?php $balances = $portfolio['balances'] ?? []; ?>
            <?php if (empty($balances)): ?>
                <div class="empty-state">
                    <img src="/assets/img/empty/orders.svg" alt="暂无持仓">
                    <p>暂未同步到持仓，可稍后刷新。</p>
                </div>
            <?php else: ?>
                <table class="table">
                    <thead>
                    <tr>
                        <th>资产</th>
                        <th>可用</th>
                        <th>冻结</th>
                        <th>总量</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($balances as $symbol => $row): ?>
                        <tr>
                            <td><?= htmlspecialchars($symbol) ?></td>
                            <td><?= htmlspecialchars((string)($row['free'] ?? $row['available'] ?? 0)) ?></td>
                            <td><?= htmlspecialchars((string)($row['locked'] ?? $row['reserved'] ?? 0)) ?></td>
                            <td><?= htmlspecialchars((string)($row['total'] ?? $row['balance'] ?? 0)) ?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div>
    </div>
</section>
<?php require __DIR__ . '/../partials/footer.php'; ?>
